#include "Configuration.h"

Configuration::Configuration(const char* fileName)
{
	FILE *f = fopen(fileName,"r");	
	if (f == NULL)
	{
		printf("Error While Opening File: %s \n",fileName);
	}
	else
	{
		/***********************************
		*	[scheduling policy]
		*	[mailer mailbox buffer size]
		*	[n]
		*	[c1][list of neighbors of node 1]
		*	[c2][list of neighbors of node 2]
		*	.....
		*	[cn][list of neighbors of node n]
		*************************************/
		fscanf(f,"%d", &m_schedulingPolicy);
		fscanf(f, "%d", &m_mailerBufferSize);
		fscanf(f, "%d", &m_numOfNudes);
		
		m_nodeGraph = new int*[m_numOfNudes];
		int neighbours = m_numOfNudes + 1;
		for(int i=0;i<m_numOfNudes;i++)
		{
			m_nodeGraph[i] = new int[neighbours];
			for(int j=0;j<neighbours;j++)
			{
				fscanf(f, "%d", &m_nodeGraph[i][j]);
			}
		}
	}
}

Configuration::~Configuration(void){}

int Configuration::getMailerBufferSize()
{
	return m_mailerBufferSize;
}

int Configuration::getNumOfNodes()
{
	return m_numOfNudes;
}

int Configuration::getSchedulingPolicy()
{
	return m_schedulingPolicy;
}

int** Configuration::getNodeGraph()
{
	return m_nodeGraph;
}

void Configuration::printConfiguration()
{
	printf("The system configuration is:\n");
	printf("Scheduling Policy: %d\n", m_schedulingPolicy);
	printf("Mailer Buffer Size: %d\n", m_mailerBufferSize);
	printf("Number of Nodes: %d\n", m_numOfNudes);
	printf("Node Graph:\n");
	for(int i=0;i<m_numOfNudes;i++)
	{
		for(int j=0;j<m_numOfNudes+1;j++)
		{
			if(!j)
				printf("Node: %d - Clock: %d - Neighbors: ", i, m_nodeGraph[i][j]);
			printf("%d ", m_nodeGraph[i][j]);
		}
		printf("\n");
	}
}
